//
//  NewsSmallImageCell.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/10.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "NewsSmallImageCell.h"
/*
 @property (weak, nonatomic) IBOutlet UIImageView *smallImageView;
 @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
 
 @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
 @property (weak, nonatomic) IBOutlet UIImageView *appraiseImageView;
 @property (weak, nonatomic) IBOutlet UILabel *appraiseLabel;
 @property (weak, nonatomic) IBOutlet UIImageView *shuXianImageView;
 
 @property (weak, nonatomic) IBOutlet UIImageView *broserImageView;
 @property (weak, nonatomic) IBOutlet UILabel *broserLabel;
 @property (weak, nonatomic) IBOutlet UIImageView *xianImageView;
 
 */
@implementation NewsSmallImageCell

- (void)awakeFromNib {
    // Initialization code
    CGFloat jht = 5;//图片上下间距
    CGFloat startWd =10;
    CGFloat jwd1 = 18;
    CGFloat jwd2 = 5;
    CGFloat jht1 = 10;//titleLabel 距离上面间距10
    _mywidth = DeviceWidth;
    _myheight = 100;
    self.smallImageView.frame = CGRectMake(10, jht, 130, _myheight-(2*jht));
    self.titleLabel.frame = CGRectMake(self.smallImageView.frame.origin.x+130+10+18, jht1, _mywidth-130-startWd-jwd1-10, 40);
    
    self.timeLabel.frame = CGRectMake(self.smallImageView.frame.origin.x+jwd1+130+10, _myheight-30, 100, 20);
    
    self.broserLabel.frame = CGRectMake(_mywidth-40, _myheight-35, 30, 20);
    self.broserImageView.frame = CGRectMake(_mywidth-62, _myheight-30, 17, 10);
    self.shuXianImageView.frame = CGRectMake(_mywidth-67, _myheight-30, 1, 10);
    self.appraiseLabel.frame = CGRectMake(_mywidth-102, _myheight-35, 30, 20);
    self.appraiseImageView.frame = CGRectMake(_mywidth-117, _myheight-30, 10, 13);
    
    self.xianImageView.frame = CGRectMake(10, _myheight-0.5, _mywidth-20, 1);
    
    self.smallImageView.layer.cornerRadius = 3.0f;
    self.smallImageView.layer.masksToBounds = YES;
    self.smallImageView.contentMode = UIViewContentModeScaleAspectFill;
     self.xianImageView.image = [UIImage imageNamed:@"labelxian"];
    
    self.appraiseImageView.hidden = YES;
    self.appraiseLabel.hidden = YES;
    self.shuXianImageView.hidden = YES;
}
-(void)setCellData:(NewsListObj *)obj
{

//     NSString *pic = [NSString stringWithFormat:@"%@_%dx%d.jpg",obj.coverImage,130,90];
    
    NSString *picStr = [NSString isEmpty:obj.coverImage]?@"":obj.coverImage;
    [self.smallImageView sd_setImageWithURL:[NSURL URLWithString:picStr] placeholderImage:kplaceholderImage130];
    self.titleLabel.text = obj.title;
    self.timeLabel.text = obj.publishTime;

    if (obj.remark>9999) {
        self.appraiseLabel.text = @"9999+";
    }
    else
    {
        self.appraiseLabel.text = NSStringFromDouble0(obj.remark);
    }
    if (obj.view>9999) {
        self.broserLabel.text = @"9999+";
    }
    else
    {
        self.broserLabel.text = NSStringFromDouble0(obj.view);
    }
   
    CGFloat width = _mywidth-10-130-15-10;
    CGFloat titleHeight = [NSString calculateTextHeight:width Content:obj.title font:themeFont14];
    CGFloat tmpHeight = titleHeight>40?40:titleHeight;
    self.titleLabel.frame = CGRectMake(self.smallImageView.frame.origin.x+130+15, 10, _mywidth-130-10-15-10, tmpHeight);
    
    CGFloat broserWidth = [NSString calculateTextWidth:18 Content:self.broserLabel.text font:themeFont11];
    CGFloat appraiseWidth = [NSString calculateTextWidth:18 Content:self.appraiseLabel.text font:themeFont11];
    
    
    self.broserLabel.frame = CGRectMake(_mywidth-broserWidth-15, _myheight-30, broserWidth, 20);
    self.broserImageView.frame = CGRectMake(self.broserLabel.frame.origin.x-17-5, _myheight-25, 17, 10);
    self.shuXianImageView.frame = CGRectMake(self.broserImageView.frame.origin.x-5, _myheight-25, 1, 10);
    self.appraiseLabel.frame = CGRectMake(self.shuXianImageView.frame.origin.x-5-appraiseWidth, _myheight-30, appraiseWidth, 20);
    self.appraiseImageView.frame = CGRectMake(self.appraiseLabel.frame.origin.x-5-10, _myheight-27, 10, 13);
    
    CGFloat startW = self.smallImageView.frame.origin.x+130+15;
    CGFloat endW = self.appraiseImageView.frame.origin.x;
    CGFloat timeWidth = MIN(120, endW-startW);
    
     self.timeLabel.frame = CGRectMake(self.smallImageView.frame.origin.x+15+130, _myheight-30, timeWidth, 20);
}

- (CGSize)sizeThatFits:(CGSize)size {
    CGFloat totalHeight = _myheight;
//    totalHeight += [self.smallImageView sizeThatFits:size].height;
//    totalHeight += 40; // margins
    
    return CGSizeMake(size.width, totalHeight);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Configure the view for the selected state
}

@end
